import QtQuick
import QtQuick.Controls
Page {
    property ListModel listmodel
    property string names
    property string tabbarname
    property string type
    property int compOfCreateVersionOrVersionControlOrMainExplanationInt: 0

    Component{
        id:compOfMountCollection
        Rectangle{
            anchors.fill: parent
            property alias textfield_nameTextAlias: textfield_name.text
            // property alias textfield_mainVersionAlias: textfield_mainVersion.text
            // property alias textfield_minorVersionAlias: textfield_minorVersion.text
            Column{
                width: parent.width
                spacing:5
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width
                        Text {
                            font.pixelSize: 20
                            anchors.fill: parent
                            text: tabbarname
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "名称"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        id:textfield_name
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "名称"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }



            }




        }


    }



    Component{
        id:compOfCreateMount

        Rectangle{
            anchors.fill: parent
            property alias textfield_nameTextAlias: textfield_name.text
            property alias combobox_localmountingCurrentIndexAlias:  combobox_localmounting.currentIndex
            property alias textfield_ipAlias: textfield_ip.text
            property alias textfield_portAlias: textfield_port.text
            Column{
                width: parent.width
                spacing:5
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width
                        Text {
                            font.pixelSize: 20
                            anchors.fill: parent
                            text: tabbarname
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "名称"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        id:textfield_name
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "名称"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }

                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "是否为本地挂载"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    ComboBox{
                        id:combobox_localmounting
                        height:parent.height-10
                        width:parent.width*0.67
                        model:["是","否"]
                        currentIndex: 0
                    }

                }
                Row{

                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "ip:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        enabled: combobox_localmounting.currentIndex===1
                        id:textfield_ip
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "ip"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "端口:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        enabled: combobox_localmounting.currentIndex===1

                        id:textfield_port
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "端口"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }

            }


        }


    }
    Component{
        id:compOfCreateVersionControl
        Rectangle{
            // anchors.fill: parent
            property alias textfield_nameTextAlias: textfield_name.text
            property alias textfield_mainVersionAlias: textfield_mainVersion.text
            property alias textfield_minorVersionAlias: textfield_minorVersion.text
            Column{
                width: parent.width
                spacing:5
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width
                        Text {
                            font.pixelSize: 20
                            anchors.fill: parent
                            text: tabbarname
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "名称"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        id:textfield_name
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "名称"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }


                Row{

                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "主版本号:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        // enabled: combobox_localmounting.currentIndex===1
                        id:textfield_mainVersion
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "主版本号"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "次版本号:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        // enabled: combobox_localmounting.currentIndex===1

                        id:textfield_minorVersion
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "次版本号"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }

            }




        }


    }

    Component{
        id:compOfCreateVersion
        Rectangle{
            // anchors.fill: parent
            property alias textfield_nameTextAlias: textfield_name.text
            property alias textfield_mainVersionAlias: textfield_mainVersion.text
            property alias textfield_minorVersionAlias: textfield_minorVersion.text
            property alias textfield_revisionVersionAlias: textfield_revisionVersion.text
            Column{
                width: parent.width
                spacing:5
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width
                        Text {
                            font.pixelSize: 20
                            anchors.fill: parent
                            text: tabbarname
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "名称"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        id:textfield_name
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "名称"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }


                Row{

                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "主版本号:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        // enabled: combobox_localmounting.currentIndex===1
                        id:textfield_mainVersion
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "主版本号"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "次版本号:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        // enabled: combobox_localmounting.currentIndex===1

                        id:textfield_minorVersion
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "次版本号"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "修正版本号:"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        // enabled: combobox_localmounting.currentIndex===1

                        id:textfield_revisionVersion
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "修正版本号"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }
            }




        }


    }

    Component{
        id:compOfCreateMainExplanation
        Rectangle{
            // anchors.fill: parent
            property alias textfield_nameTextAlias: textfield_name.text
            Column{
                width: parent.width
                spacing:5
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width
                        Text {
                            font.pixelSize: 20
                            anchors.fill: parent
                            text: tabbarname
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }
                Row{
                    spacing:5
                    width:parent.width
                    height: 50
                    Rectangle{
                        height:parent.height-10
                        width:parent.width*0.3
                        Text {
                            font.pixelSize: 15
                            anchors.fill: parent
                            text: "名称"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                    TextField{
                        id:textfield_name
                        height:parent.height-10
                        width:parent.width*0.67
                        placeholderText: "名称"
                        Material.accent: Material.Blue
                        // text: names
                    }
                }


            }




        }


    }
    Component{
        id:compOfCreateVersionOrVersionControlOrMainExplanation
        Rectangle{

            anchors.fill: parent
            Column{
                anchors.fill: parent
                Row{
                    spacing: 8
                    width: parent.width
                    height: parent.height*0.1
                    Button{
                        height: parent.height
                        width: parent.width/3-5
                        Material.accent: Material.Blue
                        Material.roundedScale: Material.SmallScale
                        highlighted: true
                        text:"添加版本控制"
                        onClicked: {
                            compOfCreateVersionOrVersionControlOrMainExplanationInt=0
                            kaddpage_swipeview.currentIndex=0
                        }
                    }
                    Button{
                        height: parent.height
                        width: parent.width/3-5
                        Material.accent: Material.Blue
                        Material.roundedScale: Material.SmallScale
                        highlighted: true
                        text:"添加版本"
                        onClicked: {
                            compOfCreateVersionOrVersionControlOrMainExplanationInt=1
                            kaddpage_swipeview.currentIndex=1
                        }
                    }
                    Button{
                        enabled: type==="mount"
                        height: parent.height
                        width: parent.width/3-5
                        Material.accent: Material.Blue
                        Material.roundedScale: Material.SmallScale
                        highlighted: true
                        text:"添加主要说明"
                        onClicked: {
                            compOfCreateVersionOrVersionControlOrMainExplanationInt=2
                            kaddpage_swipeview.currentIndex=2
                        }
                    }

                }
                // property var versionControlItem/*:*/null
                SwipeView{
                    id:kaddpage_swipeview
                    width: parent.width
                    height: parent.height*0.88
                    Component.onCompleted: {
                        var CreateVersionControl=compOfCreateVersionControl.createObject(parent)
                        var CreateVersion=compOfCreateVersion.createObject(parent)

                        kaddpage_swipeview.addItem(CreateVersionControl)
                        kaddpage_swipeview.addItem(CreateVersion)
                        var CreateMainExplanation=compOfCreateMainExplanation.createObject(parent)
                        kaddpage_swipeview.addItem(CreateMainExplanation)
                        // versionControlItem=CreateVersionControl
                        // textfield_nameTextAliasVersionControl=CreateVersionControl.textfield_nameTextAlias

                    }


                }
            }

        }

    }


    // Component:{
    //     id:compOfCreateVersionOrVersionControlOrMainExplanation


    // }

    Component.onCompleted: {


    }

    Column{
        width: parent.width*0.93
        height: parent.height*0.93
        anchors.centerIn: parent
        ScrollView{
            width: parent.width*0.9
            height: parent.height*0.79
            anchors.horizontalCenter: parent.horizontalCenter
            Loader{
                id:loader
                Component.onCompleted: {
                    console.log(type)

                }

                sourceComponent: {

                    if(type==="MountCollection"){
                        return compOfCreateMount
                    }else if(type==="VersionControl" ||type==="mount"){
                        return compOfCreateVersionOrVersionControlOrMainExplanation
                    }else if(type==="MountCollectionCreated"){
                        console.log("compOfMountCollection")
                        return compOfMountCollection

                    }

                }
                // Component.onCompleted: {
                //     console.log(type)
                // }


                anchors.fill: parent


            }
        }







        Button{
            anchors.horizontalCenter: parent.horizontalCenter
            width: parent.width*0.9
            height: parent.height*0.1
            highlighted: true
            Material.accent: Material.Blue
            Material.roundedScale: Material.SmallScale
            text:"确   定"
            onClicked: {
                console.log(type)
                switch(type){
                case "MountCollection":{
                    var mountName=loader.item.textfield_nameTextAlias
                    // var mountName=/*textfield_name.text*/
                    var mountType="mount"
                    var localMounting=(loader.item.combobox_localmountingCurrentIndexAlias===0)
                    var ip=(!localMounting)?loader.item.textfield_ipAlias:" "
                    var port=(!localMounting)?loader.item.textfield_portaAlias:0
                    console.log(localMounting,port)
                    // var mountType=
                    listmodel.append(addMount(mountType,mountName,localMounting?"true":"false",ip,port))
                    return;
                }
                case "VersionControl"||"mount":{
                    var swipeview= loader.item.children[0].children[1]
                    switch(compOfCreateVersionOrVersionControlOrMainExplanationInt){
                    case 0:{//versioncontrol
                        var swipeViewItemAt0=swipeview.itemAt(0)
                        // property alias textfield_nameTextAlias: textfield_name.text
                        // property alias textfield_mainVersionAlias: textfield_mainVersion.text
                        // property alias textfield_minorVersionAlias: textfield_minorVersion.text
                        // property alias textfield_revisionVersionAlias: textfield_revisionVersion.text
                        var swipeViewItemAt0textfield_nameTextAlias=swipeViewItemAt0.textfield_nameTextAlias
                        var swipeViewItemAt0textfield_mainVersionAlias=Number(swipeViewItemAt0.textfield_mainVersionAlias)
                        var swipeViewItemAt0textfield_minorVersionAlias=Number(swipeViewItemAt0.textfield_minorVersionAlias)
                        listmodel.append(addVersionControl("VersionControl",
                                                           swipeViewItemAt0textfield_nameTextAlias,
                                                           swipeViewItemAt0textfield_mainVersionAlias,
                                                           swipeViewItemAt0textfield_minorVersionAlias
                                                           ))
                        return;
                    }
                    case 1:{//version
                        var swipeViewItemAt1=swipeview.itemAt(1)
                        var swipeViewItemAt1textfield_nameTextAlias=swipeViewItemAt1.textfield_nameTextAlias
                        var swipeViewItemAt1textfield_mainVersionAlias=Number(swipeViewItemAt1.textfield_mainVersionAlias)
                        var swipeViewItemAt1textfield_minorVersionAlias=Number(swipeViewItemAt1.textfield_minorVersionAlias)
                        var swipeViewItemAt1textfield_revisionVersionAlias=Number(swipeViewItemAt1.textfield_revisionVersionAlias)
                        listmodel.append(addVersion("Version",
                                                    swipeViewItemAt1textfield_nameTextAlias,
                                                    swipeViewItemAt1textfield_mainVersionAlias,
                                                    swipeViewItemAt1textfield_minorVersionAlias,
                                                    swipeViewItemAt1textfield_revisionVersionAlias
                                                    ))
                        return;
                    }
                    case 2:{//mainexplanation

                        var swipeViewItemAt2=swipeview.itemAt(2)
                        var swipeViewItemAt2textfield_nameTextAlias=swipeViewItemAt2.textfield_nameTextAlias
                        console.log(swipeViewItemAt2textfield_nameTextAlias)
                        listmodel.append(addVersionControl("MainExplanation",
                                                           swipeViewItemAt2textfield_nameTextAlias,
                                                           0,
                                                           0,
                                                           ))
                        // listModelToObject(kCodeNestTreeView_ListModel)
                        return;
                    }
                    }


                    // listmodel.append(addVersionControl("VersionControl","test","1","1"))
                    return;
                }
                case "MountCollectionCreated":{
                    var mountCollectionName=loader.item.textfield_nameTextAlias
                    var mountCollectionType="MountCollection";
                    var newMountCollection= {"type":mountCollectionType,"name":mountCollectionName,"mount":[]}//addMountCollection(mountCollectionName,mountCollectionType)
                     // console.log(listmodel)
                    listmodel.append(newMountCollection)

                    // compOfMountCollection
                    return;
                }

                }



                // console.log(listmodel)
            }
        }
    }



}
